﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.News.Control
{
    public partial class TinLienQuanSubColumn : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            if (M.UrlQuery.newsID.HasValue)
            {
                New news = C.NewsController.GetByID(M.UrlQuery.newsID.Value);
                HCDataContext db = new HCDataContext();
                var result = from a in db.News
                             where a.DateCreated < news.DateCreated
                                && a.DisplayInLang == C.LanguageController.GetLanguageCurrent()
                             orderby a.DateCreated descending
                             select a;
                ListView1.DataSource = result.Take(7).ToList();
                ListView1.DataBind();
            }
        }

        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                //string title = (string)DataBinder.Eval(e.Item.DataItem, "Title");
                //Literal litText = e.Item.FindControl("litText") as Literal;
                //litText.Text = M.Common.StringCut(title, 25);
            }
        }
    }
}